home *** CD-ROM | disk | FTP | other *** search
/ Ham Radio 2000 #1 / Ham Radio 2000.iso / ham2000 / packet / p_aa4re / bb212src / bbsettb.pas < prev    next >
Encoding:
Pascal/Delphi Source File  |  1989-02-19  |  10.3 KB  |  386 lines

  1. {$M 8192,128000,655360} {Stack, minheap, maxheap}
  2. PROGRAM bbsettnc;
  3. (*===========================================================================*)
  4. (*                                                                           *)
  5. (*   Copyright 1988, 1989 by H. Roy Engehausen.  All rights reserved.        *)
  6. (*   This software may be freely distributed and used, but it may not        *)
  7. (*   under any circumstances be sold by anyone other than the author.        *)
  8. (*   It may be distributed by a commercial company as long as it is          *)
  9. (*   for no cost.                                                            *)
  10. (*                                                                           *)
  11. (*   Permission is explicity granted to use this code as a model for         *)
  12. (*   other programs as long as they carry this copyright notice and the      *)
  13. (*   imbedded copyright constants                                            *)
  14. (*                                                                           *)
  15. (*===========================================================================*)
  16.  
  17. {$R+}    {Range checking on}
  18. {$B-}    {Boolean complete evaluation off}
  19. {$S+}    {Stack checking on}
  20. {$I+}    {I/O checking on}
  21. {$V+}    {String var checks}
  22. {$F+}    {Must have far calls}
  23. {$N-}    {No numeric coprocessor}
  24.  
  25. (*===========================================================================*)
  26. (* Globals                                                                   *)
  27. (*===========================================================================*)
  28.  
  29. USES
  30.   CRT,
  31.   DOS,
  32.   bbdummy,
  33.   bbfsm,
  34.   bbstr;
  35.  
  36. (*===========================================================================*)
  37. (* Constants                                                                 *)
  38. (*===========================================================================*)
  39.  
  40. CONST
  41.   in_file_name = 'BBOPT.BB';
  42.  
  43.  
  44. (*===========================================================================*)
  45. (* Imported definitions                                                      *)
  46. (*===========================================================================*)
  47.  
  48. {$I 8250CON.PAS}
  49. {$I BBOTYPE.PAS}
  50.  
  51. (*===========================================================================*)
  52. (* Vars                                                                      *)
  53. (*===========================================================================*)
  54.  
  55. VAR
  56.  
  57.   com_done    : ARRAY[1..50] OF INTEGER;
  58.   com_count   : BYTE;
  59.   com_index   : BYTE;
  60.   in_file     : FILE OF opt_file_rec;
  61.   opt_buffer  : opt_file_rec;
  62.   p_cnt       : BYTE;
  63.   r           : registers;
  64.  
  65. (*===========================================================================*)
  66. (* Send/Receive a PC/TNC                                                     *)
  67. (*===========================================================================*)
  68.  
  69. PROCEDURE sr_pcpa(s : STRING);
  70.  
  71.   VAR
  72.     i : BYTE;
  73.  
  74.   BEGIN;
  75.  
  76.     WITH opt_buffer.opt_port_file, r DO
  77.       BEGIN;
  78.  
  79.         i := 0;
  80.  
  81.         WHILE i < LENGTH(s) DO
  82.           BEGIN;
  83.  
  84.             i := i + 1;
  85.  
  86.             AH := 1;
  87.             AL := ORD(s[i]);
  88.  
  89.             INTR(com_number, r);
  90.  
  91.             IF AH = 1 THEN
  92.               WRITE(CHR(AL));
  93.  
  94.           END;
  95.  
  96.         i := 0;
  97.  
  98.         REPEAT
  99.           INC(i);
  100.  
  101.           AX := 0;
  102.  
  103.           INTR(com_number, r);
  104.  
  105.           IF AH = 1 THEN
  106.             BEGIN;
  107.               WRITE(CHR(AL));
  108.               i := 0;
  109.             END;
  110.  
  111.         UNTIL i = 250;
  112.  
  113.       END;
  114.  
  115.   END;
  116.  
  117. (*===========================================================================*)
  118. (* Send a string to the TNC                                                  *)
  119. (*===========================================================================*)
  120.  
  121. PROCEDURE send_tnc(s : STRING);
  122.  
  123.   VAR
  124.     i : BYTE;
  125.  
  126.   BEGIN;
  127.  
  128.     WITH opt_buffer.opt_port_file, r DO
  129.       BEGIN;
  130.  
  131.         IF port_type = port_pcpa THEN
  132.           BEGIN;
  133.             sr_pcpa(s);
  134.             EXIT;
  135.           END;
  136.  
  137.         i := 0;
  138.  
  139.         WHILE i < LENGTH(s) DO
  140.           BEGIN;
  141.  
  142.             i := i + 1;
  143.  
  144.             AH := 1;
  145.             AL := ORD(s[i]);
  146.             DX := com_number - 1;
  147.  
  148.             INTR(tnc_interrupt, r);
  149.  
  150.           END;
  151.  
  152.       END;
  153.  
  154.   END;
  155.  
  156. (*===========================================================================*)
  157. (* Receive all data from the TNC and throw it away                           *)
  158. (*===========================================================================*)
  159.  
  160. PROCEDURE discard_tnc;
  161.  
  162.   BEGIN;
  163.  
  164.     WITH opt_buffer.opt_port_file, r DO
  165.       BEGIN;
  166.  
  167.         IF port_type = port_pcpa THEN
  168.           BEGIN;
  169.             sr_pcpa('');
  170.             EXIT;
  171.           END;
  172.  
  173.         WHILE TRUE DO
  174.           BEGIN;
  175.  
  176.             AH := 3;
  177.             DX := com_number - 1;
  178.  
  179.             INTR(tnc_interrupt, r);
  180.  
  181.             AH := AH AND lsr_8250_dr;
  182.  
  183.             IF AH = 0 THEN EXIT;
  184.  
  185.             AH := 2;
  186.             DX := com_number - 1;
  187.  
  188.             INTR(tnc_interrupt, r);
  189.  
  190.             WRITE(CHR(AL));
  191.  
  192.           END;
  193.       END;
  194.  
  195.   END;
  196.  
  197. (*===========================================================================*)
  198. (* Do a port                                                                 *)
  199. (*===========================================================================*)
  200.  
  201. PROCEDURE do_port;
  202.   VAR
  203.     i : BYTE;
  204.  
  205.   BEGIN;
  206.  
  207.     WITH opt_buffer.opt_port_file, r DO
  208.       BEGIN;
  209.  
  210.         FOR com_index := 1 TO com_count DO
  211.           IF com_done[com_index] = com_number THEN
  212.             EXIT;
  213.  
  214.         INC(com_count);
  215.         com_done[com_count] := com_number;
  216.  
  217.         WRITELN;
  218.         WRITELN('Setting up COM', com_number);
  219.         WRITELN;
  220.  
  221.         IF port_type <> port_pcpa THEN
  222.           BEGIN;
  223.             AH := 4;
  224.             DX := com_number - 1;
  225.             INTR(tnc_interrupt, r);
  226.             IF AX <> $AA55 THEN
  227.               BEGIN;
  228.                 WRITELN;
  229.                 WRITELN('***** ERROR *****');
  230.                 WRITELN('MBBIOS not active for this COM port');
  231.                 HALT(1);
  232.               END;
  233.           END;
  234.  
  235.         AH := 0;
  236.  
  237.         CASE data_rate OF
  238.           110  : AL := 0;
  239.           150  : AL := $20;
  240.           300  : AL := $40;
  241.           600  : AL := $60;
  242.           1200 : AL := $80;
  243.           2400 : AL := $A0;
  244.           4800 : AL := $C0;
  245.           9600 : AL := $E0;
  246.         END;
  247.  
  248.         IF port_type <> port_pc1xx THEN
  249.           AL := AL OR $03;
  250.  
  251.         DX := com_number - 1;
  252.  
  253.         IF port_type <> port_pcpa THEN
  254.           INTR(tnc_interrupt, r);
  255.  
  256.         IF port_host_only THEN
  257.           EXIT;
  258.  
  259.         IF port_type = port_aeapk232 THEN
  260.           BEGIN;
  261.             FOR i := 1 TO 3 DO
  262.               BEGIN;
  263.                 discard_tnc;
  264.                 send_tnc('*');
  265.                 DELAY(1000);
  266.               END;
  267.             DELAY(1000);
  268.           END;
  269.  
  270.         discard_tnc;
  271.  
  272.         IF port_type <> port_aeapk232 THEN
  273.           send_tnc(^A^A^I^Q^X^['JHOST1'^M)
  274.         ELSE
  275.           BEGIN;
  276.             send_tnc(#$11);
  277.             DELAY(10);
  278.             send_tnc(#$18);
  279.             DELAY(10);
  280.             send_tnc(#$03);
  281.             DELAY(10);
  282.             send_tnc('HO');
  283.             DELAY(10);
  284.             send_tnc('ST');
  285.             DELAY(10);
  286.             send_tnc(' Y');
  287.             DELAY(10);
  288.             send_tnc(cr);
  289.           END;
  290.  
  291.         DELAY(1000);
  292.  
  293.         discard_tnc;
  294.  
  295.         IF port_type <> port_aeapk232 THEN
  296.           send_tnc(#01#01#01'@B');
  297.  
  298.         IF port_type <> port_aeapk232 THEN
  299.           send_tnc(^A^A^I^Q^X^['JHOST1'^M)
  300.         ELSE
  301.           send_tnc(#$01#$01#$4F#$47#$47#$17);
  302.  
  303.         DELAY(1000);
  304.  
  305.         discard_tnc;
  306.  
  307.         DELAY(1000);
  308.  
  309.         discard_tnc;
  310.  
  311.       END;
  312.  
  313.   END;
  314.  
  315. (*===========================================================================*)
  316. (* Main program begins here                                                  *)
  317. (*===========================================================================*)
  318.  
  319. BEGIN
  320.  
  321.   WRITELN(this_bbs_version);
  322.   WRITELN('Copyright 1988, 1989, H.R. Engehausen.                          ');
  323.   WRITELN('This software may be freely distributed and used, but it may not');
  324.   WRITELN('under any circumstances be sold by anyone other than the author.');
  325.   WRITELN('It may be distributed by a commercial company as long as it is  ');
  326.   WRITELN('for no cost.                                                    ');
  327.  
  328.   (*-------------------------------------------------------------------------*)
  329.   (* Initialize                                                              *)
  330.   (*-------------------------------------------------------------------------*)
  331.  
  332.   com_count := 0;
  333.  
  334.   (*-------------------------------------------------------------------------*)
  335.   (* Open the file                                                           *)
  336.   (*-------------------------------------------------------------------------*)
  337.  
  338.   ASSIGN(in_file, in_file_name);
  339.  
  340.   {$I-}
  341.   RESET(in_file);
  342.   {$I+}
  343.   IF IORESULT <> 0 THEN
  344.     BEGIN;
  345.       WRITELN;
  346.       WRITELN('***** Cannot open ', in_file_name);
  347.       WRITELN;
  348.       HALT(1);
  349.     END;
  350.  
  351.   READ(in_file, opt_buffer);
  352.   opt_block := opt_buffer.opt_block_file;
  353.  
  354.   (*-------------------------------------------------------------------------*)
  355.   (* Verify option block                                                     *)
  356.   (*-------------------------------------------------------------------------*)
  357.  
  358.   WITH opt_block DO
  359.     IF parm_file_ver <> this_bbs_parms THEN
  360.       BEGIN;
  361.         WRITELN;
  362.         WRITELN('Incorrect version of the PARMS.BB has been found.');
  363.         WRITELN('Expected ', this_bbs_parms,
  364.                 ' but got ', parm_file_ver, '.');
  365.      WRITELN('Rerun the proper version of BBSETUP that matches this program');
  366.         WRITELN;
  367.         WRITELN;
  368.         HALT(1);
  369.       END;
  370.  
  371.   (*-------------------------------------------------------------------------*)
  372.   (* Process the ports                                                       *)
  373.   (*-------------------------------------------------------------------------*)
  374.  
  375.   p_cnt := opt_buffer.opt_block_file.port_count;
  376.   WHILE p_cnt > 0 DO
  377.     BEGIN;
  378.       DEC(p_cnt);
  379.       READ(in_file, opt_buffer);
  380.       do_port;
  381.     END;
  382.  
  383.   CLOSE(in_file);
  384.  
  385. END.
  386.